package com.ruoyi.common.core.enums;

import com.ruoyi.common.core.exception.CustomException;

/**
 * 海外销售渠道服务商枚举
 */
public enum DspChannelEnum {
    KLCLUB("KLCLUB", "KLClub", CountryEnum.HK),
    MEIMAI("MEIMAI", "美卖", CountryEnum.TW),
    FKMalls("FKMalls", "福猫", CountryEnum.CN),
    GMS("GMS", "GMS", CountryEnum.SG),
    Blidz("Blidz", "Blidz", CountryEnum.US),
    Thisshop("Thisshop", "Thisshop", CountryEnum.TH),
    Meiya("Meiya", "Meiya", CountryEnum.CN),
    ;

    private final String channel;
    private final String name;
    private final CountryEnum country;

    DspChannelEnum(String channel, String name, CountryEnum country) {
        this.channel = channel;
        this.name = name;
        this.country = country;
    }

    public String getChannel() {
        return channel;
    }

    public String getName() {
        return name;
    }

    public CountryEnum getCountry() {
        return country;
    }

    public static String getNameByChannel(String channel) {
        for (DspChannelEnum item : DspChannelEnum.values()) {
            if (item.getChannel().equals(channel)) {
                return item.getName();
            }
        }
        return "";
    }

    public static CountryEnum getCountryByChannel(String channel) {
        for (DspChannelEnum item : DspChannelEnum.values()) {
            if (item.getChannel().equals(channel)) {
                return item.getCountry();
            }
        }

        throw new CustomException(channel + " channel not exists");
    }

    public static DspChannelEnum parse(String channel) {
        for (DspChannelEnum item : DspChannelEnum.values()) {
            if (item.getChannel().equals(channel)) {
                return item;
            }
        }
        return null;
    }

    public static DspChannelEnum parseByName(String name) {
        for (DspChannelEnum item : DspChannelEnum.values()) {
            if (item.getName().equals(name)) {
                return item;
            }
        }
        return null;
    }
}
